package com.mkyong.config;

import com.mongodb.Mongo;
import java.net.UnknownHostException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoFactoryBean;
import org.springframework.data.mongodb.core.MongoTemplate;

/**
 * Spring MongoDB configuration file
 *
 */
@Configuration
public class SpringMongoConfig {

    public @Bean
    Mongo mongo() throws UnknownHostException {
        return new Mongo("localhost");
    }

    public @Bean
    MongoTemplate mongoTemplate() throws Exception {
        return new MongoTemplate(mongo(), "mydb");
    }

    public @Bean
    MongoFactoryBean mongoFactoryBean() {
        MongoFactoryBean mongo = new MongoFactoryBean();
        mongo.setHost("localhost");
        return mongo;
    }
}
